function bucketTaget(x, y, w, h, targetColor, main, tabs) {
  if (x > w || x < 0 || y > h || y < 0) return;
  if (tabs.find((item) => item.x == x && item.y == y)) return;
  tabs.push({ x, y });
  let target = main.pxMap.find((p) => p.x == x && p.y == y);

  if (target && target.color == targetColor) {
    target.color = main.pointColor;
    target.alpha = 1;
  } else return false;
  bucketTaget(x - 1, y, w, h, targetColor, main, tabs);
  bucketTaget(x + 1, y, w, h, targetColor, main, tabs);
  bucketTaget(x, y - 1, w, h, targetColor, main, tabs);
  bucketTaget(x, y + 1, w, h, targetColor, main, tabs);
}

export default function (pxs, main) {
  if (main.isUp) return;
  if (pxs.length == 0) return;
  let px = pxs[0];
  let targetColor = px.color;
  let x = px.x;
  let y = px.y;
  let w = main.width;
  let h = main.height;
  let tabs = [];
  if (px.color == main.pointColor) return;
  bucketTaget(x, y, w, h, targetColor, main, tabs);
  main.drawGraphics();
}